home *** CD-ROM | disk | FTP | other *** search
- (*
- The ListBox component (Standard palette) in the
- original Delphi release failed to publish an OnChange
- event. This is the event generated any time the user
- moves the list box cursor bar and probably the most
- important list box event.
-
- This component is derived from the ListBox class and
- incorporates and publishes the OnChange event.
-
- To add this component to your VCL, do the following:
-
- 1. Compile this file.
- 2. Make sure the resulting DCU is where Delphi
- can find it.
- 3. Place the bitmap file (LBOX.DCR) with the
- DCU file.
- 4. Use the Install Components item of the Options
- menu to install.
-
- Jeeze, did Borland make it easy or what???!!
-
- *)
-
-
- UNIT Lbox;
-
- INTERFACE
-
- USES
- SysUtils, WinTypes, Messages, Classes, Controls, Graphics, Forms,
- Menus, StdCtrls;
-
- Type
- TMyListBox = Class(TListBox)
- private
- FOnChange : TNotifyEvent;
- FLastSel : integer;
- procedure Click; override;
- protected
- procedure Change; Virtual;
- published
- property OnChange : TNotifyEvent read FOnChange write FOnChange;
- public
- constructor create(AOwner : TComponent); override;
- End;
-
- Procedure Register;
-
- IMPLEMENTATION
-
- procedure TMyListBox.Change;
- begin
- FLastSel := ItemIndex;
- if assigned(FOnChange) then FOnChange(self);
- end;
-
- procedure TMyListBox.Click;
- begin
- inherited Click;
- if FLastSel <> ItemIndex then
- Change;
- end;
-
- constructor TMyListBox.Create;
- begin
- Inherited Create(AOwner);
- FLastSel := -1;
- end;
-
- procedure Register;
- begin
- RegisterComponents('Newlin',[TMyListBox]);
- end;
-
- END.
-